package com.cn.gxa.springjpa.dao;


import com.cn.gxa.springjpa.bean.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;

@Repository//   注入给spring管理
//<bean  name="userDao"  class=" com.cn.gxa.springjpa.dao.UserDao"
public interface UserDao extends JpaRepository<User,Integer>, JpaSpecificationExecutor<User> {//对接 数据库的
    //JpaSpecificationExecutor  自定义注解 crud
    //写方法的规则
   //怎么自己定义查询语句
    //'
    List<User> findByUsernameContaining(String username);

    List<User> findByUsernameStartsWith(String username);

    List<User> findByUsernameEndsWith(String username);

    //  select  .........  where  username  like ?  and  password=?
    List<User>  findByUsernameContainingAndPassword(String username,String  password);

    List<User>  findByBirthdayAfter(Date  birthday);

    List<User>  findAllByOrderByAuth();

//
        @Modifying  //  实体类的名字  hibernate 操作实体类
        @Query("update  User u set u.auth = :auth where u.id=:id")
        @Transactional
        void updateUserAuth(@Param("auth") String auth,@Param("id") Integer  no);

}
